package com.ctwom.algorithm.questions.Escene;

/**
 * 7个人轮班，每个人一天要公平，周末每个人都要轮上一天
 */
public class OrderArrangeWork {
    public static void main(String[] args) {
        int[][] arr = {{1, 2, 3, 4, 5, 6, 7}, {1, 1, 1, 1, 1, 1, 1}};
        orderArrangeWork(arr, 55);
    }

    /**
     * 先倒序排序，然后每一个去周末加班加一，然后再倒排以此类推
     *
     * @param arr  哪些人
     * @param days 排多少天
     */
    public static void orderArrangeWork(int[][] arr, int days) {
        while (days >= 7) {
            //1、倒序排序
            int length = arr[1].length;
            for (int i = 0; i < length; i++) {
                int max = arr[1][i];
                for (int j = i; j < length; j++) {
                    if (arr[1][j] > max) {
                        max = arr[1][i];
                        swap(arr, j, i);
                    }
                }
            }
            //2、开始上班
            for (int i = 1; i <= 7; i++) {
                if (i % 7 == 6) {//周6
                    arr[1][5]++;
                }
                if (i % 7 == 0) {//周7
                    arr[1][6]++;
                }
            }
            //3、打印每周的上班结果
            for (int i = 0; i < 7; i++) {
                System.out.print(arr[0][i] + ",");
            }
            System.out.println();
            for (int i = 0; i < 7; i++) {
                System.out.print(arr[1][i] + ",");
            }
            System.out.println();
            days -= 7;
        }
        //4、打印最后7天之内的上班结果
        for (int i = 0; i < days; i++) {
            System.out.print(arr[0][i] + ",");
        }
        System.out.println();
        for (int i = 0; i < days; i++) {
            System.out.print(arr[1][i] + ",");
        }
    }

    public static void swap(int[][] arr, int j, int i) {
        int tmp0 = arr[0][j];
        int tmp1 = arr[1][j];
        arr[0][j] = arr[0][i];
        arr[1][j] = arr[1][i];
        arr[0][i] = tmp0;
        arr[1][i] = tmp1;
    }
}
